package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;

/************************************************************************************
 * @File name :DefaultWapper.java
 * @Author : zhouyi
 * @Date : 2015年6月1日
 * @Copyright : 洋码头
 ************************************************************************************/
public class ImDefaultWapper {
	SqlManager manage;


	public ImDefaultWapper() {
		manage = new SqlManager("mysql");
	}
	/**根据msgid查找插入的记录*/
	
	public List<Map> selectImInfo(int SellerId,int UserId,int MsgId) throws InterruptedException {
		if(manage==null|| !manage.getEnv().equals("mysql"))
		{
			manage = new SqlManager("mysql");
		}
		int Number=SellerId+UserId;
		Map m = new HashMap();
		m.put("bid", Number%64);
		m.put("msgid", MsgId);
		List<Map> pia = manage.getSelectResults(
				"com.ymttest.database.mapping.ImDefaultMapper.selectImInfo", m);
		return pia;
	}	
	/**根据FromUserId、ToUserId查找记录*/
	public List<Map> selectTotalCount(int SellerId,int UserId) throws InterruptedException {
		if(manage==null||!manage.getEnv().equals("mysql2"))
		{
			manage = new SqlManager("mysql2");
		}
		Map m = new HashMap();
		m.put("sid", SellerId);
		m.put("uid", UserId);
		m.put("tid", UserId%64);
		//Logger.debug(m);
		List<Map> pia = manage.getSelectResults(
				"com.ymttest.database.mapping.ImDefaultMapper.selectTotalCount", m);
		return pia;
	}	
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) throws InterruptedException {
		
	//Logger.debug(new ImDefaultWapper().selectImInfo(SellerId, UserId, MsgId, Limit));
	ImDefaultWapper im = new ImDefaultWapper();
	Logger.debug(im.selectTotalCount(288484,1113));
	Logger.debug(im.selectTotalCount(1113,288484));
	}
}
